package com.hngy.xpq.persondemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.os.Bundle;
import android.widget.Button;

import com.hngy.xpq.persondemo.adapter.ListAdapter;
import com.hngy.xpq.persondemo.assets.XpqIcoMoon;
import com.hngy.xpq.persondemo.assets.XpqIcoMoonUtils;
import com.hngy.xpq.persondemo.bean.Op;
import com.hngy.xpq.persondemo.opActivity.BjActivity;
import com.hngy.xpq.persondemo.opActivity.DwActivity;
import com.hngy.xpq.persondemo.opActivity.SkActivity;
import com.hngy.xpq.persondemo.opActivity.SzActivity;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    Button favorites,recording,wallet,order;    //功能
    RecyclerView r2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        favorites = findViewById(R.id.XPQ_FAVORITES);
        recording = findViewById(R.id.XPQ_RECORDING);
        wallet = findViewById(R.id.XPQ_WALLET);
        order = findViewById(R.id.XPQ_ORDER);
        r2 = findViewById(R.id.r1);
        // 上层图标
        favorites.setText(XpqIcoMoon.FAVORITES);
        recording.setText(XpqIcoMoon.RECORDING);
        wallet.setText(XpqIcoMoon.WALLET);
        order.setText(XpqIcoMoon.ORDER);
        XpqIcoMoonUtils.setIOC(favorites,recording,wallet,order);
        // 获取操作模块数据
        List<Op> list = getListOp();
        // 操作模块布局
        listAdapter(list);
    }

    private List<Op> getListOp() {
        List<Op> list = new ArrayList<>();
        String[] icon = {XpqIcoMoon.MAKE, XpqIcoMoon.ENTER, XpqIcoMoon.POSITION, XpqIcoMoon.SET};
        String[] name = {"书库", "笔记", "定位", "设置"};
        Object[] acl = {SkActivity.class, BjActivity.class, DwActivity.class, SzActivity.class};
        for (int i = 0; i < icon.length; i++) {
            Op o = new Op(icon[i], name[i], acl[i]);
            list.add(o);
        }
        return list;
    }

    // 初始化布局
    private void listAdapter(List<Op> list) {
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL);
        r2.setLayoutManager(layoutManager);
        ListAdapter adapter = new ListAdapter(list);
        r2.setAdapter(adapter);
    }

}